<!DOCTYPE html>
<html lang="zh">
<head>
	<th:block th:include="include :: header('标签 & 提示')" />
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeIn">
	<div class="row">
		<div class="col-sm-6">
			<div class="ibox float-e-margins">
				<div class="ibox-title">
					<h5>证书私钥（KEY）</h5>
				</div>
				<div class="ibox-content">
					<textarea id="keyContent" class="form-control" style="height: 600px;">[[*{sslKeyContent}]]</textarea>
					<div style="display: flex;">
						<div onclick="copyToClipboard('key')" class="btn btn-info btn-rounded btn-block" style="margin-top: 10px;"><i class="fa fa-copy"></i> 复制内容</div>
						<div style="width: 10px; height: 100%;"></div>
						<div onclick="douwnloadFile('key')" class="btn btn-primary btn-rounded btn-block" style="margin-top: 10px;"><i class="fa fa-download"></i> 下载KEY文件</div>
					</div>

				</div>
			</div>
		</div>

		<div class="col-sm-6">
			<div class="ibox float-e-margins">
				<div class="ibox-title">
					<h5>证书PEM</h5>
				</div>
				<div class="ibox-content">
					<textarea id="pemContent" class="form-control" style="height: 600px;">[[*{sslPemContent}]]</textarea>
					<div style="display: flex;">
						<div onclick="copyToClipboard('pem')" class="btn btn-info btn-rounded btn-block" style="margin-top: 10px;"><i class="fa fa-copy"></i> 复制内容</div>
						<div style="width: 10px; height: 100%;"></div>
						<div onclick="douwnloadFile('pem')" class="btn btn-primary btn-rounded btn-block" style="margin-top: 10px;"><i class="fa fa-download"></i> 下载证书PEM文件</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
	function copyToClipboard(text) {
		if(text === 'key'){
			text = $("#keyContent").val();
		}else if(text === 'pem'){
			text = $("#pemContent").val();
		}
		var textarea = document.createElement('textarea');
		textarea.style.position = 'fixed';
		textarea.style.opacity = 0;
		textarea.value = text;
		document.body.appendChild(textarea);
		textarea.select();
		document.execCommand('copy');
		document.body.removeChild(textarea);
		$.modal.msgSuccess("复制成功！");
	}

	function douwnloadFile(type){
		var downLoadUrl = "http://";
		var fileArray = "[[${sslApply.sslFilePath}]]".split(",");
		var url = new URL(window.location.href);
		if(url.port === 80){
			downLoadUrl += url.hostname;
		}else{
			downLoadUrl += url.hostname+":"+url.port
		}
		if(type === 'key'){
			downLoadUrl += "/profile/upload/"+fileArray[0];
		}else if(type === 'pem'){
			downLoadUrl += "/profile/upload/"+fileArray[1];
		}
		//创建a标签点击
		var temp = document.createElement("a");
		temp.href = downLoadUrl;
		temp.target = "_bank";
		temp.style.display = "none";
		document.body.appendChild(temp);
		temp.click();
		document.body.removeChild(temp);
	}
</script>
</body>
</html>
